<?php

namespace App\Providers;

use DB;
use Queue;
use Blade;
use App\Models\Testc;
use Illuminate\Support\ServiceProvider;
use Illuminate\View\Compilers\BladeCompiler;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        \Carbon\Carbon::setLocale('zh');
        view()->share('key', 'petty');
        Blade::directive('datetime', function ($expression) {
            return "<?php echo with{$expression}->format('m/d/Y H:i'); ?>";
        });
        DB::listen(function ($query) {
            // file_put_contents('./log.txt', $query->sql, FILE_APPEND);
            // file_put_contents('./log.txt', $query->time, FILE_APPEND);
        });
        Testc::creating(function ($testc) {
            $testc->uid = 12;
        });
        Queue::after(function ($event) {
            //
            echo '任务结束了。。哈哈。。。';
        });
        Queue::failing(function ($event) {
            // Notify team of failing job...
            echo '任务失败了...';
        });
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}
